package com.ruoyi.tracks.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tracks.domain.TracksTags;
import com.ruoyi.tracks.service.ITracksTagsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 歌曲tagController
 * 
 * @author lin
 * @date 2025-03-04
 */
@RestController
@RequestMapping("/tracks/trackTags")
public class TracksTagsController extends BaseController
{
    @Autowired
    private ITracksTagsService tracksTagsService;

    /**
     * 查询歌曲tag列表
     */
    @PreAuthorize("@ss.hasPermi('tracks:trackTags:list')")
    @GetMapping("/list")
    public TableDataInfo list(TracksTags tracksTags)
    {
        startPage();
        List<TracksTags> list = tracksTagsService.selectTracksTagsList(tracksTags);
        return getDataTable(list);
    }

    /**
     * 导出歌曲tag列表
     */
    @PreAuthorize("@ss.hasPermi('tracks:trackTags:export')")
    @Log(title = "歌曲tag", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TracksTags tracksTags)
    {
        List<TracksTags> list = tracksTagsService.selectTracksTagsList(tracksTags);
        ExcelUtil<TracksTags> util = new ExcelUtil<TracksTags>(TracksTags.class);
        util.exportExcel(response, list, "歌曲tag数据");
    }

    /**
     * 获取歌曲tag详细信息
     */
    @PreAuthorize("@ss.hasPermi('tracks:trackTags:query')")
    @GetMapping(value = "/{trackId}")
    public AjaxResult getInfo(@PathVariable("trackId") Long trackId)
    {
        return success(tracksTagsService.selectTracksTagsByTrackId(trackId));
    }

    /**
     * 新增歌曲tag
     */
    @PreAuthorize("@ss.hasPermi('tracks:trackTags:add')")
    @Log(title = "歌曲tag", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TracksTags tracksTags)
    {
        return toAjax(tracksTagsService.insertTracksTags(tracksTags));
    }

    /**
     * 修改歌曲tag
     */
    @PreAuthorize("@ss.hasPermi('tracks:trackTags:edit')")
    @Log(title = "歌曲tag", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TracksTags tracksTags)
    {
        return toAjax(tracksTagsService.updateTracksTags(tracksTags));
    }

    /**
     * 删除歌曲tag
     */
    @PreAuthorize("@ss.hasPermi('tracks:trackTags:remove')")
    @Log(title = "歌曲tag", businessType = BusinessType.DELETE)
	@DeleteMapping("/{trackIds}")
    public AjaxResult remove(@PathVariable Long[] trackIds)
    {
        return toAjax(tracksTagsService.deleteTracksTagsByTrackIds(trackIds));
    }
}
